package dailyTopic;

import java.util.Arrays;

/**
 * @author zhangmin
 * @create 2021-07-19 9:49
 */
public class maxFrequency1838 {
    public int maxFrequency(int[] nums, int k) {
        Arrays.sort(nums);
        int n=nums.length;
        int l=0,res=1;
        long sum=0;
        for (int r=1;r<n;r++){
            sum+=(long) (nums[r]-nums[r-1])*(r-l);
            System.out.println("sum="+sum);
            if (sum>k){
                sum-=(nums[r]-nums[l]);
                l++;
                System.out.println("sum1="+sum);
            }
            res=Math.max(res,r-l+1);
            System.out.println("res="+res);
        }
        return res;
    }
   /* public static void main(String[] args) {
        int[] nums1=new int[]{1,4,8,13};
        //int[] nums2=new int[]{2,3,5};
        dailyTopic.maxFrequency1838 object=new dailyTopic.maxFrequency1838();
        System.out.println(object.maxFrequency(nums1,5));
    }*/
}
